$(function () {
    $('.withdraw-order-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要完成订单吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/cms/orders/withdraw_order_success/',
                    'data':{
                        'order_id':order_id
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                            zlalert.alertError(data['message']);
                        }
                    }
                })
            }
        })
    })
});




$(function () {
    $('.withdraw-cancel-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要取消订单吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/cms/orders/withdraw_order_cancel/',
                    'data':{
                        'order_id':order_id
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                            zlalert.alertInfo(data['message']);
                        }
                    }
                })
            }
        })
    })
});



$(function () {
    $(".trade-img-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#trade-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var savebtn = dialog.find("#save-trade-btn");

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});




$(function () {
    $('#save-trade-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#trade-dialog');

        var pay_img = $("input[name='pay_img']").val();

        var submitType = self.attr("data-type");
        var order_id = self.attr('data-id');


        zlajax.post({
            'url': '/cms/upload_pay_img/',
            'data':{
                'order_id':order_id,
                'pay_img':pay_img,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});


// 修改注释
$(function () {
    $(".withdraw-annotate-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#withdraw-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var annotate = tr.attr("data-annotate");
        if (annotate == 'None'){
            annotate = ''
        }

        var annotateInput = $("input[name='annotate']");

        var savebtn = dialog.find("#save-withdraw-btn");

        annotateInput.val(annotate);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-user_id",tr.attr('data-user_id'));
    })
});




$(function () {
    $('#save-withdraw-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#withdraw-dialog');

        var annotate = $("input[name='annotate']").val();
        var submitType = self.attr("data-type");
        var user_id = self.attr('data-user_id');

        zlajax.post({
            'url': '/cms/orders/reset_annotate/',
            'data':{
                'annotate':annotate,
                'user_id':user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});